#pragma once
#include <map>
#include <string>
#include <iostream>

class State {
protected:
	State* Next;	//改变状态对象

public:
	State() : Next(nullptr) {};
	virtual ~State() {};

public:
	virtual void DoWork1() = 0;
	virtual void DoWork2() = 0;
	//DoWork3 ...

	State* GetNext() { return Next; };
};

//State 对象共享, 使用享元模式(flyweight)
class StatesMapping {
public:
	static std::map<std::string, State*> StatesMap;
};

//ConcreteState1 状态对象1
class ConcreteState1 : public State {
public:
	ConcreteState1() : State() {};
	~ConcreteState1() {};

public:
	virtual void DoWork1() override {
		std::cout << "ConcreteState1 DoWork1" << std::endl;
		//TODO...
		Next = StatesMapping::StatesMap["ConcreteState2"];
	}

	virtual void DoWork2() override {
		std::cout << "ConcreteState1 DoWork2" << std::endl;
		//TODO...
		Next = StatesMapping::StatesMap["ConcreteState1"];
	}
};


//ConcreteState1 状态对象2
class ConcreteState2 : public State {
public:
	ConcreteState2() : State() {};
	~ConcreteState2() {};

public:
	virtual void DoWork1() override {
		std::cout << "ConcreteState2 DoWork1" << std::endl;
		//TODO...
		Next = StatesMapping::StatesMap["ConcreteState1"];
	}

	virtual void DoWork2() override {
		std::cout << "ConcreteState2 DoWork2" << std::endl;
		//TODO...
		Next = StatesMapping::StatesMap["ConcreteState2"];
	}
};

//ConcreteState3 ...

std::map<std::string, State*> StatesMapping::StatesMap = { {"ConcreteState1", new ConcreteState1()}, {"ConcreteState2", new ConcreteState2()} };